#include <bits/stdc++.h>
// 2025/01/23
// tag: 
// Author: Zhang Muen
using namespace std;

int64_t n, population[101];
unordered_map<int, vector<int>> tree;
bool vis[101];

int64_t bfs(int begin){
    memset(vis, 0, sizeof(vis));
    queue<int> q;
    q.push(begin);
    vis[begin] = true;
    int64_t s = 0, l = 0;
    while (!q.empty()){
        int size = q.size();
        for (int i = 0; i < size; i++){
            int x = q.front();
            q.pop();
            s += population[x] * l;
            for (auto y: tree[x])
                if (!vis[y])
                    vis[y] = true, q.push(y);
        }
        l++;
    }
    return s;
}

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> population[i];
        int x, y;
        cin >> x >> y;
        if (x)
            tree[i].push_back(x), tree[x].push_back(i);
        if (y)
            tree[i].push_back(y), tree[y].push_back(i);
    }
    int64_t ans = INT64_MAX;
    for (int i = 1; i <= n; i++)
        ans = min(ans, bfs(i));
    cout << ans;
    return 0;
}